/* *************************************************************
 * JStockChart : an extension of JFreeChart for financial market
 * *************************************************************
 * 
 * Copyright (C) 2010, by Sha Jiang.
 * 
 * Project Info: http://code.google.com/p/jstockchart
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * 
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. in the
 * United States and other countries.]
 */
package org.jstockchart.data;

import java.io.Serializable;
import java.util.Date;

/**
 * Represents one data item in a time series.
 * 
 * @author Sha Jiang
 * @date 2010-05-15
 */
public class TimeseriesItem implements Serializable, Comparable<TimeseriesItem> {

	private static final long serialVersionUID = 7983915051327695560L;

	private Date time = null;

	private Double price = null;

	private Double average = null;

	private Double volumn = null;

	public TimeseriesItem(Date time, Double price, Double average, Double volumn) {
		this.time = time;
		this.price = price;
		this.average = average;
		this.volumn = volumn;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Double getAverage() {
		return average;
	}

	public void setAverage(Double average) {
		this.average = average;
	}

	public Double getVolumn() {
		return volumn;
	}

	public void setVolumn(Double volumn) {
		this.volumn = volumn;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((average == null) ? 0 : average.hashCode());
		result = prime * result + ((price == null) ? 0 : price.hashCode());
		result = prime * result + ((time == null) ? 0 : time.hashCode());
		result = prime * result + ((volumn == null) ? 0 : volumn.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TimeseriesItem other = (TimeseriesItem) obj;
		if (average == null) {
			if (other.average != null)
				return false;
		} else if (!average.equals(other.average))
			return false;
		if (price == null) {
			if (other.price != null)
				return false;
		} else if (!price.equals(other.price))
			return false;
		if (time == null) {
			if (other.time != null)
				return false;
		} else if (!time.equals(other.time))
			return false;
		if (volumn == null) {
			if (other.volumn != null)
				return false;
		} else if (!volumn.equals(other.volumn))
			return false;
		return true;
	}

	public int compareTo(TimeseriesItem item) {
		return getTime().compareTo(item.getTime());
	}
}
